/**
 * 首页、我们、联系我们页面
 */

$(document).ready(
    function () {
        // 获取主机地址之后的目录
        var curWwwPath = window.document.location.href;

        //我们团队文章显示控制
        var isShow = 0;

        //产品展示图片
        var productDisplayNum = 0;

        var bigImageTag = 0;

        /**
         * 获取项目根路径
         *
         * @returns {string} 返回路径地址
         */
        function getRootPath() {
            //获取当前网址，如： http://localhost:8083/uimcardprj/share/meun.jsp
            var curWwwPath = window.document.location.href;
            //获取主机地址之后的目录，如： uimcardprj/share/meun.jsp
            var pathName = window.document.location.pathname;
            var pos = curWwwPath.indexOf(pathName);
            //获取主机地址，如： http://localhost:8083
            var localhostPaht = curWwwPath.substring(0, pos);
            //获取带"/"的项目名，如：/uimcardprj
            var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
            return (localhostPaht + projectName);
        }


        //判断是否是首页
        var pathName = window.document.location.pathname;
        if (curWwwPath.indexOf("/index.html") > 0) {
            $(function () {
                $.ajax({
                    type: "POST",
                    async: false,
                    url: getRootPath() + "/HWT.do",
                    data: "oneClass=Home",
                    success: function (data) {

                        //定义脚本显示次数
                        var scriptCount = 0;
                        //遍历产品展示变量
                        var p1 = 0;
                        //遍历数据
                        $.each(data.data, function (key, article) {
                            var sum = 0;
                            //首页大图遍历
                            if (article.twoClass == 'LargerVersion') {
                                $.each(article.resource, function (key, resources) {

                                    if (bigImageTag == 0) {
                                        $("#largerVersionDiv").append('<div class="item active"><a href=adv.html?conId=' + resources.artId + '><img src=resource/image/' + resources.pathName + '></a></div>');
                                    } else {
                                        $("#largerVersionDiv").append('<div class="item"><a  href=adv.html?conId=' + resources.artId + '><img src=resource/image/' + resources.pathName + '></a></div>');
                                    }
                                    bigImageTag++;
                                });
                            }
                            //最新活动遍历
                            else if (article.twoClass == 'LatestActivity') {
                                $("#latestActivityContextP").append(article.content);
                                $.each(article.resource, function (key, resources) {
                                    $("#latestActivityImage").attr("src", 'resource/image/' + article.resource[0].pathName)
                                });
                            }
                            //产品展示
                            else if (article.twoClass == 'ProductContent') {
                                $("#productDisplayP").append(article.content);
                            }//产品展示图片
                            else if (article.twoClass == 'ProductDisplay') {

                                $.each(article.resource, function (key, resources) {
                                    if (productDisplayNum == 0) {
                                        $("#FontScroll ul").append('<li>');
                                    }
                                    $("#FontScroll ul li:eq(" + p1 + ")").append('<a href=adv.html?conId=' + resources.artId + '><img src=resource/image/' + resources.pathName + ' /></a>');
                                    productDisplayNum++;
                                    if (productDisplayNum == 4) {
                                        p1++;
                                        productDisplayNum = 0;
                                    }
                                });

                            }

                            //我们
                            else if (article.twoClass == 'We') {
                                $("#weContextP").append(article.content);
                                $.each(article.resource, function (key, resources) {
                                    $("#weImage").append(' <li class="col-xs-6 p"><a href="us.html"><img src=resource/image/' + resources.pathName + ' /></a></li>');
                                });
                            }
                        });
                        $('#FontScroll').FontScroll({time: 3000, num: 1});
                    }
                });
            });

        } else if (curWwwPath.indexOf("/us.html") > 0) {
            $.ajax({
                type: "POST",
                async: false,
                url: getRootPath() + "/HWT.do",
                data: "twoClass=Well",
                success: function (data) {
                    $.each(data.data, function (key, article) {
                        //顶部大图
                        if (article.oneClass == 'TopBigImage') {
                            $.each(article.resource, function (key, resources) {
                                $("#usTopBig").attr("src", "resource/image/" + resources.pathName);
                            });
                        }
                        //我们团队
                        else if (article.oneClass == 'WellPage') {
                            $("#weContentP").append(article.content);
                        }
                        //我们的能力
                        else if (article.oneClass == 'Ability') {
                            $("#abilityContextP").append(article.content);
                        }
                        //我们的合作伙伴
                        else if (article.oneClass == 'Partner') {
                            $("#partnerContextP").append(article.content);
                            $.each(article.resource, function (key, resources) {
                                $("#partnerImageDiv").append('<div class="banquan p col-lg-4"><dl class=""><dt><img src=resource/image/' + resources.pathName + ' /></dt> <dd>' + resources.name + '</dd> </dl> </div>');
                            });
                            $("#partnerImageDiv").append(' <a href="" class="more">点击更多</a>');
                        }//我们的荣誉
                        else if (article.oneClass == 'Honor') {
                            $("#honorContextP").append(article.content);
                            $.each(article.resource, function (key, resources) {
                                $("#honorImageDiv").append('<div class="banquan p col-lg-4"><dl class=""><dt><img src=resource/image/' + resources.pathName + ' /></dt> <dd>' + resources.name + '</dd> </dl> </div>');
                            });
                        }
                        //我们团队文章
                        else if (article.oneClass == 'OurTeamContent') {
                            isShow++;
                            if (isShow == 1) {
                                $("#weContextShowDiv").append('<div class="p col-lg-6 col-md-6 col-sm-12 col-xs-12 teamh">' +
                                    '<div class="teamz">' +
                                    '<div class="col-lg-8 p col-md-8 col-xs-12 col-sm-6">' +
                                    '<img src=resource/image/' + article.resource[0].pathName + ' ></div> ' +
                                    '<div class="word p col-lg-4 col-md-4 col-sm-6 col-xs-12">' +
                                    '<h6>' + article.titleName + '</h6>' +
                                    '<em></em>' +
                                    '<span>' + article.content + '</span>' +
                                    '<a href=adv.html?conId=' + article.resource[0].artId + '>更多介绍</a></div></div></div>');
                            } else if (isShow == 2) {
                                $("#weContextShowDiv").append('<div class="p col-lg-6 col-md-6 col-sm-12 col-xs-12 teaml">' +
                                    '<div class="teamz">' +
                                    '<div class="col-lg-8 p col-md-8 col-xs-12 col-sm-6">' +
                                    '<img src=resource/image/' + article.resource[0].pathName + ' ></div>' +
                                    '<div class="word p col-lg-4 col-md-4 col-sm-6 col-xs-12">' +
                                    '<h6>' + article.titleName + '</h6>' +
                                    '<em></em>' +
                                    '<span>' + article.content + '</span>' +
                                    '<a href=adv.html?conId=' + article.resource[0].artId + '>更多介绍</a></div></div></div>');
                            } else if (isShow == 3) {
                                $("#weContextShowDiv").append('<div class="p col-lg-6 col-md-6 col-sm-12 col-xs-12 teaml">' +
                                    '<div class="teamz">' +
                                    '<div class="col-lg-8 p col-md-8 col-xs-12 col-sm-6">' +
                                    '<img src=resource/image/' + article.resource[0].pathName + ' ></div>' +
                                    '<div class="word p col-lg-4 col-md-4 col-sm-6 col-xs-12">' +
                                    '<h6>' + article.titleName + '</h6>' +
                                    '<em></em>' +
                                    '<span>' + article.content + '</span>' +
                                    '<a href=adv.html?conId=' + article.resource[0].artId + '>更多介绍</a></div></div></div>');
                            } else if (isShow == 4) {
                                $("#weContextShowDiv").append('<div class="p col-lg-6 col-md-6 col-sm-12 col-xs-12 teamh">' +
                                    '<div class="teamz">' +
                                    '<div class="col-lg-8 p col-md-8 col-xs-12 col-sm-6">' +
                                    '<img src=resource/image/' + article.resource[0].pathName + ' ></div> ' +
                                    '<div class="word p col-lg-4 col-md-4 col-sm-6 col-xs-12">' +
                                    '<h6>' + article.titleName + '</h6>' +
                                    '<em></em>' +
                                    '<span>' + article.content + '</span>' +
                                    '<a href=adv.html?conId=' + article.resource[0].artId + '>更多介绍</a></div></div></div>');
                            }

                        }
                    });
                    $("#weContextShowDiv").append('<div class="clear"></div>');
                }
            });
        } else if (curWwwPath.indexOf("/come.html") > 0) {
            $.ajax({
                type: "POST",
                async: false,
                url: getRootPath() + "/HWT.do",
                data: "oneClass=Contact",
                success: function (data) {
                    //二维码显示控制
                    var sum = 0;
                    //获取数据
                    $.each(data.data, function (key, article) {
                        //顶部大图
                        if (article.sorting == 1) {
                            $("#joinTopBigImage").attr("src", "resource/image/" + article.resource[0].pathName);
                        }
                        //公司介绍
                        else if (article.sorting == 2) {
                            $("#gsjs").append(article.titleName);
                            $("#introduceP").append(article.content);
                            $("#introduceImage").attr("src", "resource/image/" + article.resource[0].pathName);
                            //article.resource[0].pathName
                        }
                        //企业理念
                        else if (article.sorting == 3) {
                            $("#qyln").append(article.titleName);
                            $("#conceptContext").append(article.content);
                            $("#conceptImage").attr("src", "resource/image/" + article.resource[0].pathName);
                        }
                        //发展历程
                        else if (article.sorting == 4) {
                            $("#fzlc").append(article.titleName);
                            $("#courseContext").append(article.content);
                            $("#courseImage").attr("src", "resource/image/" + article.resource[0].pathName);
                        }
                        //加入玖扬
                        else if (article.sorting == 5) {
                            $("#comejy").append(article.titleName);
                            $("#joinContext").append(article.content);
                            $("#joinImage").attr("src", "resource/image/" + article.resource[0].pathName);
                        }
                        //联系我们
                        else if (article.sorting == 6) {
                            $("#tellPhone").text(article.titleName);
                            $("#tellContext").append(article.content);
                            $.each(article.resource, function (key, resources) {
                                if (sum == 0) {
                                    $("#tellContext").after('<div class="row code" id="showQR">');
                                }
                                $("#showQR").append('<dl class="col-xs-12 col-lg-4"><dt>' + resources.name + '</dt><dd><img src=resource/image/' + resources.pathName + '></dd></dl>');
                                sum++;
                                if (sum == 3) {
                                    sum = 0;
                                }
                            });
                        }
                    });
                }
            });
        }

    });